/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.attence;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutySection;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-22
 */
@Service("dutysectionService")
public class DutySectionServiceImpl implements DutySectionService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of DutySection
     ****************************************/
    public void insert(DutySection dutysection) throws Exception {
        dutysection.setSectionid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(dutysection);
    }

    /****************************************
     * Update a instace of DutySection
     ****************************************/
    public void update(DutySection dutysection) throws Exception {
        iDataSet4iBatis.update(dutysection);
    }

    /****************************************
     * Delete a instace of DutySection
     ****************************************/
    public void delete(DutySection dutysection) throws Exception {
        iDataSet4iBatis.delete(dutysection);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(DutySection dutysection) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(DutySection dutysection) throws Exception {
        String statementId = dutysection.getStatmentId();
        String mainId = dutysection.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> dutysectionList = new ArrayList<BaseModel>();
        for (String id : ids) {
            DutySection model = new DutySection();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            dutysectionList.add(model);
        }
        iDataSet4iBatis.batchDelete(dutysectionList);
    }

    /****************************************
     * Query instaces of DutySection
     ****************************************/
    public List<BaseModel> queryAsList(DutySection dutysection) throws Exception {
        String queryListStatement = "";
        if (dutysection.isPaging()) {
            queryListStatement = dutysection.getStatmentId();
            dutysection.setStatmentId("DutySection.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(dutysection);
            dutysection.setTotalCount(baseModel.getTotalCount());
            dutysection.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(dutysection);
    }

    /****************************************
     * Query a instaces of DutySection
     ****************************************/
    public BaseModel queryAsObject(DutySection dutysection) throws Exception {
        return iDataSet4iBatis.queryAsObject(dutysection);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
